/*
 * 添加用户交易
 * 参数   交易码：trancode=1012
 * 
 */

package org.ccams.tran;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.ccams.domain.User;
/**
 * 添加用户交易
 * @author liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 */
public class Tran1012 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String userName = (String) request.getParameter("userName");
		String loginName = (String) request.getParameter("loginName");
		String passWord = (String) request.getParameter("passWord");
		String email = (String) request.getParameter("email");
		String rId = (String) request.getParameter("rId");
		System.out.println("rId="+rId);//输出
		rId = (rId != null) ? rId : "1";//容错
		
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		User u = new User();
		u.setEmail(email);
		u.setLoginName(loginName);
		u.setPassWord(passWord);
		u.setRId(Long.parseLong(rId));//转换成整型
		u.setUserName(userName);
		int i = getCcamsService().getUserDao().insertUser(u);
		if (i == 1) {
			success = true;
			message = "用户添加成功";
		} else {
			success = false;
			message = "用户添加失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
